<template>
  <div class="container">
    <h3>检测依据</h3>
<el-form>


    <el-tabs
      v-model="activeName"
      type="border-card"
      style="margin-top: 20px"
      @tab-click="handleClick"
    >
      <el-tab-pane label="中药材" name="中药材">
        <el-row>
          <el-col :span="7">
            <el-input
              placeholder="请输入关键词"
              v-model.trim="searchName1"
              style="width: 300px"
            >
              <i slot="prefix" class="el-input__icon el-icon-search"></i>
              <el-button slot="append" @click="handleSearch1">搜索</el-button>
            </el-input>
          </el-col>
          <el-button style="float: right; margin-right: 10px" @click="download"
            >模板下载</el-button
          >
          <el-upload
            class="upload-daoru"
            ref="upload"
            :action="action"
            :on-change="uploadonchange"
            accept=".xlsx,.xls"
            :show-file-list="false"
            :auto-upload="false"
          >
            <el-button slot="trigger" size="small">导入模板</el-button>
          </el-upload>
          <el-button
            type="primary"
            style="float: right; margin-right: 10px"
            v-if="added"
            @click="handleadded"
            >新增</el-button
          >
        </el-row>
        <el-table
          :data="tableData1"
          border
          style="margin-top: 20px"
          ref="multipleTable"
          header-cell-class-name="table-header"
        >
          <el-table-column prop="checkName" sortable label="标准名称"></el-table-column>
          <el-table-column prop="createTime" sortable label="添加时间"></el-table-column>
          <!-- <el-table-column prop="standard" sortable label="标准类型"></el-table-column> -->
          <el-table-column prop="basis" sortable label="附件">
            <template slot-scope="scope">
              <el-button type="text" @click="handlecheck(scope.$index, scope.row)">{{
                scope.row.basis
              }}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="stateful" sortable label="状态"></el-table-column>
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="edit"
                @click="handleEdit(scope.$index, scope.row)"
                >编辑</el-button
              >
              <el-button type="text">
                <el-dropdown style="color: #409eff; font-size: 12px">
                  <span class="el-dropdown-link"> 更多 </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        style="color: black"
                        v-show="disable"
                        v-if="state == scope.row.state"
                        @click="disabled(scope.$index, scope.row)"
                        >禁用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        v-show="disable"
                        v-if="state == scope.row.state ? 0 : 1"
                        @click="start(scope.$index, scope.row)"
                        >启用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        style="color: red"
                        v-if="del"
                        @click="handleDelete1(scope.$index, scope.row)"
                        >删除</el-button
                      >
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          layout="total, prev, pager, next, jumper"
          :page-size="pagesize"
          :current-page.sync="currentPage1"
          @current-change="handleCurrentChange1"
          :total="total1"
          style="margin-top: 20px"
        ></el-pagination>
      </el-tab-pane>
      <el-tab-pane label="辅料" name="辅料">
        <el-row>
          <el-col :span="7">
            <el-input
              style="width: 300px"
              placeholder="请输入关键词"
              v-model.trim="searchName2"
            >
              <i slot="prefix" class="el-input__icon el-icon-search"></i>
              <el-button slot="append" @click="handleSearch2">搜索</el-button>
            </el-input>
          </el-col>
          <el-button style="float: right; margin-right: 10px" @click="download"
            >模板下载</el-button
          >
          <el-upload
            class="upload-daoru"
            ref="upload"
            :action="action"
            :on-change="uploadonchange"
            accept=".xlsx,.xls"
            :show-file-list="false"
            :auto-upload="false"
          >
            <el-button slot="trigger" size="small">导入模板</el-button>
          </el-upload>
          <el-button
            type="primary"
            style="float: right; margin-right: 10px"
            v-if="added"
            @click="handleadded"
            >新增</el-button
          >
        </el-row>

        <el-table
          :data="tableData2"
          border
          style="margin-top: 20px"
          ref="multipleTable"
          header-cell-class-name="table-header"
        >
          <el-table-column prop="checkName" sortable label="标准名称"></el-table-column>
          <el-table-column prop="createTime" sortable label="添加时间"></el-table-column>
          <!-- <el-table-column prop="standard" sortable label="标准类型"></el-table-column> -->
          <el-table-column prop="basis" sortable label="附件">
            <template slot-scope="scope">
              <el-button type="text" @click="handlecheck(scope.$index, scope.row)">{{
                scope.row.basis
              }}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="stateful" sortable label="状态"></el-table-column>
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="edit"
                @click="handleEdit(scope.$index, scope.row)"
                >编辑</el-button
              >
              <el-button type="text">
                <el-dropdown style="color: #409eff; font-size: 12px">
                  <span class="el-dropdown-link"> 更多 </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        style="color: black"
                        v-show="disable"
                        v-if="state == scope.row.state"
                        @click="disabled(scope.$index, scope.row)"
                        >禁用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        v-show="disable"
                        v-if="state == scope.row.state ? 0 : 1"
                        @click="start(scope.$index, scope.row)"
                        >启用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        style="color: red"
                        v-if="del"
                        @click="handleDelete1(scope.$index, scope.row)"
                        >删除</el-button
                      >
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          layout="total, prev, pager, next, jumper"
          :page-size="pagesize"
          :current-page.sync="currentPage2"
          @current-change="handleCurrentChange2"
          :total="total2"
          style="margin-top: 20px"
        ></el-pagination>
      </el-tab-pane>
      <el-tab-pane label="提取饮片" name="提取饮片">
        <el-row>
          <el-col :span="7">
            <el-input
              style="width: 300px"
              placeholder="请输入关键词"
              v-model.trim="searchName3"
            >
              <i slot="prefix" class="el-input__icon el-icon-search"></i>
              <el-button slot="append" @click="handleSearch3">搜索</el-button>
            </el-input>
          </el-col>
          <el-button style="float: right; margin-right: 10px" @click="download"
            >模板下载</el-button
          >
          <el-upload
            class="upload-daoru"
            ref="upload"
            :action="action"
            :on-change="uploadonchange"
            accept=".xlsx,.xls"
            :show-file-list="false"
            :auto-upload="false"
          >
            <el-button slot="trigger" size="small">导入模板</el-button>
          </el-upload>
          <el-button
            type="primary"
            style="float: right; margin-right: 10px"
            v-if="added"
            @click="handleadded"
            >新增</el-button
          >
        </el-row>

        <el-table
          :data="tableData3"
          border
          style="margin-top: 20px"
          ref="multipleTable"
          header-cell-class-name="table-header"
        >
          <el-table-column prop="checkName" sortable label="标准名称"></el-table-column>
          <el-table-column prop="createTime" sortable label="添加时间"></el-table-column>
          <!-- <el-table-column prop="standard" sortable label="标准类型"></el-table-column> -->
          <el-table-column prop="basis" sortable label="附件">
            <template slot-scope="scope">
              <el-button type="text" @click="handlecheck(scope.$index, scope.row)">{{
                scope.row.basis
              }}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="stateful" sortable label="状态"></el-table-column>
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="edit"
                @click="handleEdit(scope.$index, scope.row)"
                >编辑</el-button
              >
              <el-button type="text">
                <el-dropdown style="color: #409eff; font-size: 12px">
                  <span class="el-dropdown-link"> 更多 </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        v-if="state == scope.row.state"
                        style="color: black"
                        v-show="disable"
                        @click="disabled(scope.$index, scope.row)"
                        >禁用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        v-show="disable"
                        v-if="state == scope.row.state ? 0 : 1"
                        @click="start(scope.$index, scope.row)"
                        >启用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        style="color: red"
                        v-if="del"
                        @click="handleDelete1(scope.$index, scope.row)"
                        >删除</el-button
                      >
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          layout="total, prev, pager, next, jumper"
          :page-size="pagesize"
          :current-page.sync="currentPage3"
          @current-change="handleCurrentChange3"
          :total="total3"
          style="margin-top: 20px"
        ></el-pagination>
      </el-tab-pane>
      <el-tab-pane label="配方颗粒(浸膏粉)" name="配方颗粒(浸膏粉)">
        <el-row>
          <el-col :span="7">
            <el-input
              style="width: 300px"
              placeholder="请输入关键词"
              v-model.trim="searchName6"
            >
              <i slot="prefix" class="el-input__icon el-icon-search"></i>
              <el-button slot="append" @click="handleSearch6">搜索</el-button>
            </el-input>
          </el-col>
          <el-button style="float: right; margin-right: 10px" @click="download"
            >模板下载</el-button
          >
          <el-upload
            class="upload-daoru"
            ref="upload"
            :action="action"
            :on-change="uploadonchange"
            accept=".xlsx,.xls"
            :show-file-list="false"
            :auto-upload="false"
          >
            <el-button slot="trigger" size="small">导入模板</el-button>
          </el-upload>
          <el-button
            type="primary"
            style="float: right; margin-right: 10px"
            v-if="added"
            @click="handleadded"
            >新增</el-button
          >
        </el-row>

        <el-table
          :data="tableData6"
          border
          style="margin-top: 20px"
          ref="multipleTable"
          header-cell-class-name="table-header"
        >
          <el-table-column prop="checkName" sortable label="标准名称"></el-table-column>
          <el-table-column prop="createTime" sortable label="添加时间"></el-table-column>
          <!-- <el-table-column prop="standard" sortable label="标准类型"></el-table-column> -->
          <el-table-column prop="basis" sortable label="附件">
            <template slot-scope="scope">
              <el-button type="text" @click="handlecheck(scope.$index, scope.row)">{{
                scope.row.basis
              }}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="stateful" sortable label="状态"></el-table-column>
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="edit"
                @click="handleEdit(scope.$index, scope.row)"
                >编辑</el-button
              >
              <el-button type="text">
                <el-dropdown style="color: #409eff; font-size: 12px">
                  <span class="el-dropdown-link"> 更多 </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        style="color: black"
                        v-show="disable"
                        v-if="state == scope.row.state"
                        @click="disabled(scope.$index, scope.row)"
                        >禁用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        v-show="disable"
                        v-if="state == scope.row.state ? 0 : 1"
                        @click="start(scope.$index, scope.row)"
                        >启用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        style="color: red"
                        v-if="del"
                        @click="handleDelete1(scope.$index, scope.row)"
                        >删除</el-button
                      >
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          layout="total, prev, pager, next, jumper"
          :page-size="pagesize"
          :current-page.sync="currentPage6"
          @current-change="handleCurrentChange6"
          :total="total6"
          style="margin-top: 20px"
        ></el-pagination>
      </el-tab-pane>
      <el-tab-pane label="配方颗粒(颗粒)" name="配方颗粒(颗粒)">
        <el-row>
          <el-col :span="6">
            <el-input
              style="width: 300px"
              placeholder="请输入关键词"
              v-model.trim="searchName5"
            >
              <i slot="prefix" class="el-input__icon el-icon-search"></i>
              <el-button slot="append" @click="handleSearch5">搜索</el-button>
            </el-input>
          </el-col>
          <el-col :span="7">
			           <el-form-item label="标准类型：" prop="standard">
                            <el-select v-model="standard"  filterable placeholder="请选择" style="width: 300px;" @change="handlechange">
                                <el-option label="国标" value="1"></el-option>
                                <el-option label='省标' value="2"></el-option>
                            </el-select>
                        </el-form-item>
			        </el-col>
          <el-button style="float: right; margin-right: 10px" @click="download"
            >模板下载</el-button
          >
          <el-upload
            class="upload-daoru"
            ref="upload"
            :action="action"
            :on-change="uploadonchange"
            accept=".xlsx,.xls"
            :show-file-list="false"
            :auto-upload="false"
          >
            <el-button slot="trigger" size="small">导入模板</el-button>
          </el-upload>
          <el-button
            type="primary"
            style="float: right; margin-right: 10px"
            v-if="added"
            @click="handleadded"
            >新增</el-button
          >
        </el-row>

        <el-table
          :data="tableData5"
          border
          style="margin-top: 20px"
          ref="multipleTable"
          header-cell-class-name="table-header"
        >
          <el-table-column prop="checkName" sortable label="标准名称"></el-table-column>
          <el-table-column prop="createTime" sortable label="添加时间"></el-table-column>
          <el-table-column prop="standard" sortable label="标准类型"></el-table-column>
          <el-table-column prop="basis" sortable label="附件">
            <template slot-scope="scope">
              <el-button type="text" @click="handlecheck(scope.$index, scope.row)">{{
                scope.row.basis
              }}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="stateful" sortable label="状态"></el-table-column>
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="edit"
                @click="handleEdit(scope.$index, scope.row)"
                >编辑</el-button
              >
              <el-button type="text">
                <el-dropdown style="color: #409eff; font-size: 12px">
                  <span class="el-dropdown-link"> 更多 </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        v-if="state == scope.row.state"
                        style="color: black"
                        v-show="disable"
                        @click="disabled(scope.$index, scope.row)"
                        >禁用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        v-show="disable"
                        v-if="state == scope.row.state ? 0 : 1"
                        @click="start(scope.$index, scope.row)"
                        >启用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        style="color: red"
                        v-if="del"
                        @click="handleDelete5(scope.$index, scope.row)"
                        >删除</el-button
                      >
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          layout="total, prev, pager, next, jumper"
          :page-size="pagesize"
          :current-page.sync="currentPage5"
          @current-change="handleCurrentChange5"
          :total="total5"
          style="margin-top: 20px"
        ></el-pagination>
      </el-tab-pane>
      <el-tab-pane label="配方颗粒" name="配方颗粒">
        <el-row>
          <el-col :span="7">
            <el-input
              style="width: 300px"
              placeholder="请输入关键词"
              v-model.trim="searchName4"
            >
              <i slot="prefix" class="el-input__icon el-icon-search"></i>
              <el-button slot="append" @click="handleSearch4">搜索</el-button>
            </el-input>
          </el-col>
          <el-button style="float: right; margin-right: 10px" @click="download"
            >模板下载</el-button
          >
          <el-upload
            class="upload-daoru"
            ref="upload"
            :action="action"
            :on-change="uploadonchange"
            accept=".xlsx,.xls"
            :show-file-list="false"
            :auto-upload="false"
          >
            <el-button slot="trigger" size="small">导入模板</el-button>
          </el-upload>
          <el-button
            type="primary"
            style="float: right; margin-right: 10px"
            v-if="added"
            @click="handleadded"
            >新增</el-button
          >
        </el-row>

        <el-table
          :data="tableData4"
          border
          style="margin-top: 20px"
          ref="multipleTable"
          header-cell-class-name="table-header"
        >
          <el-table-column prop="checkName" sortable label="标准名称"></el-table-column>
          <el-table-column prop="createTime" sortable label="添加时间"></el-table-column>
          <!-- <el-table-column prop="standard" sortable label="标准类型"></el-table-column> -->
          <el-table-column prop="basis" sortable label="附件">
            <template slot-scope="scope">
              <el-button type="text" @click="handlecheck(scope.$index, scope.row)">{{
                scope.row.basis
              }}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="stateful" sortable label="状态"></el-table-column>
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="edit"
                @click="handleEdit(scope.$index, scope.row)"
                >编辑</el-button
              >
              <el-button type="text">
                <el-dropdown style="color: #409eff; font-size: 12px">
                  <span class="el-dropdown-link"> 更多 </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        v-if="state == scope.row.state"
                        style="color: black"
                        v-show="disable"
                        @click="disabled(scope.$index, scope.row)"
                        >禁用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        v-show="disable"
                        v-if="state == scope.row.state ? 0 : 1"
                        @click="start(scope.$index, scope.row)"
                        >启用</el-button
                      >
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button
                        type="text"
                        style="color: red"
                        v-if="del"
                        @click="handleDelete4(scope.$index, scope.row)"
                        >删除</el-button
                      >
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          layout="total, prev, pager, next, jumper"
          :page-size="pagesize"
          :current-page.sync="currentPage4"
          @current-change="handleCurrentChange4"
          :total="total4"
          style="margin-top: 20px"
        ></el-pagination>
      </el-tab-pane>
    </el-tabs>
    <big-img v-if="showImg" @clickit="viewImg" :imgSrc="imgSrc"></big-img>
    </el-form>
  </div>
</template>

<script>
import axios from "axios";

import BigImg from "../../../common/BigImg.vue";
import { check_list, check_delete, check_update } from "@/request/api";
import { check_import } from "@/request/manageapi.js";
export default {
  props: ["activeName1"],
  components: { "big-img": BigImg },
  beforeRouteLeave(to, form, next) {
    next();
  },
  data() {
    return {
      standard:"1",
      showImg: false,
      imgSrc: "",
      state: 0,
      currentPage1: 1,
      currentPage2: 1,
      currentPage3: 1,
      currentPage4: 1,
      currentPage5: 1,
      currentPage6: 1,
      pagesize: 10,
      total1: 0,
      total2: 0,
      total3: 0,
      total4: 0,
      total5: 0,
      total6: 0,
      searchName1: "",
      searchName2: "",
      searchName3: "",
      searchName4: "",
      searchName5: "",
      searchName6: "",
      activeName: "中药材",
      tableData1: [],
      tableData2: [],
      tableData3: [],
      tableData4: [],
      tableData5: [],
      tableData6: [],
      boxCode: "",
      boxCode1: "",
      added: true,
      edit: true,
      disable: true,
      del: true,
      action: "",
    };
  },
  created() {
    var data = JSON.stringify(this.$store.state.jcyj);
    var a = "新增";
    var b = "编辑";
    var c = "禁用";
    var d = "删除";
    // if (data.indexOf(a) != -1) {
    //   this.added = true;
    // } else {
    //   this.added = false;
    // }
    // if (data.indexOf(b) != -1) {
    //   this.edit = true;
    // } else {
    //   this.edit = false;
    // }

    // if (data.indexOf(c) != -1) {
    //   this.disable = true;
    // } else {
    //   this.disable = false;
    // }
    // if (data.indexOf(d) != -1) {
    //   this.del = true;
    // } else {
    //   this.del = false;
    // }
  },
  mounted() {
    // this.init1();
    // this.init2();
    // this.init3();
    // this.init4();
    // this.init5();
    // console.log(this.$store.state.type)
    // this.init6();
    if (this.$store.state.type == "" || this.$store.state.type == null) {
    } else {
      this.activeName = this.$store.state.type;
    }
  },
  destroyed: function () {
    this.$store.commit("settype", "");
  },
  methods: {
    handlechange(){
      this.init5()
    },
    handlecheck(index, row) {
      this.showImg = true; // 获取当前图片地址
      this.imgSrc = this.$store.state.imageUrls + row.basis;
    },
    viewImg() {
      this.showImg = false;
    },
    start(index, row) {
      this.$confirm("确定启用该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        row.state = 0;
        let formdata = new FormData();
        for (var a in row) {
          if (row[a] == null || row[a] == "null") {
            row[a] = "";
            formdata.append(a, "");
          } else {
            formdata.append(a, row[a]);
          }
        }
        check_update(formdata).then((res) => {
          this.$notify({
            title: "操作成功",
            message: "启用成功",
            type: "success",
          });
          this.init1();
          this.init2();
          this.init3();
          this.init4();
          this.init5();
        });
      });
    },
    disabled(index, row) {
      this.$confirm("确定禁用该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        row.state = 1;
        let formdata = new FormData();
        for (var a in row) {
          if (row[a] == null || row[a] == "null") {
            row[a] = "";
            formdata.append(a, "");
          } else {
            formdata.append(a, row[a]);
          }
        }
        check_update(formdata).then((res) => {
          this.$notify({
            title: "操作成功",
            message: "禁用成功",
            type: "success",
          });
          this.init1();
          this.init2();
          this.init3();
          this.init4();
          this.init5();
        });
      });
    },
    init1() {
      check_list({
        page: this.currentPage1,
        type: "中药材",
        checkName: this.searchName1,
        companyId: this.activeName1,
      }).then((res) => {
        this.tableData1 = res.rows;
        this.total1 = res.total;
        var _this = this;
        for (let i = 0; i < this.tableData1.length; i++) {
          if (this.tableData1[i].standard == 1) {
            this.tableData1[i].standard = "国标";
          } else if (this.tableData1[i].standard == 2) {
            this.tableData1[i].standard = "省标";
          }
          if (this.tableData1[i].state == 0) {
            this.tableData1[i].stateful = "启用";
          } else {
            this.tableData1[i].stateful = "禁用";
          }
        }
      });
    },
    init2() {
      // console.log(this.activeName1);
      check_list({
        page: this.currentPage2,
        type: "辅料",
        query: this.searchName2,
        companyId: this.activeName1,
      }).then((res) => {
        this.tableData2 = res.rows;
        this.total2 = res.total;
        for (let i = 0; i < this.tableData2.length; i++) {
          if (this.tableData2[i].standard == 1) {
            this.tableData2[i].standard = "国标";
          } else if (this.tableData2[i].standard == 2) {
            this.tableData2[i].standard = "省标";
          }
          if (this.tableData2[i].state == 0) {
            this.tableData2[i].stateful = "启用";
          } else {
            this.tableData2[i].stateful = "禁用";
          }
        }
      });
    },
    init3() {
      check_list({
        page: this.currentPage3,
        type: "提取饮片",
        query: this.searchName3,
        companyId: this.activeName1,
      }).then((res) => {
        this.tableData3 = res.rows;
        this.total3 = res.total;
        for (let i = 0; i < this.tableData3.length; i++) {
          if (this.tableData3[i].standard == 1) {
            this.tableData3[i].standard = "国标";
          } else if (this.tableData3[i].standard == 2) {
            this.tableData3[i].standard = "省标";
          }
          if (this.tableData3[i].state == 0) {
            this.tableData3[i].stateful = "启用";
          } else {
            this.tableData3[i].stateful = "禁用";
          }
        }
      });
    },
    init4() {
      check_list({
        page: this.currentPage4,
        type: "配方颗粒",
        query: this.searchName4,
        companyId: this.activeName1,
      }).then((res) => {
        this.tableData4 = res.rows;
        this.total4 = res.total;
        for (let i = 0; i < this.tableData4.length; i++) {
          if (this.tableData4[i].standard == 1) {
            this.tableData4[i].standard = "国标";
          } else if (this.tableData4[i].standard == 2) {
            this.tableData4[i].standard = "省标";
          }
          if (this.tableData4[i].state == 0) {
            this.tableData4[i].stateful = "启用";
          } else {
            this.tableData4[i].stateful = "禁用";
          }
        }
      });
    },
    init5() {
      check_list({
        standard:this.standard,
        page: this.currentPage5,
        type: "配方颗粒(颗粒)",
        query: this.searchName5,
        companyId: this.activeName1,
      }).then((res) => {
        this.tableData5 = res.rows;
        this.total5 = res.total;
        for (let i = 0; i < this.tableData5.length; i++) {
          if (this.tableData5[i].standard == 1) {
            this.tableData5[i].standard = "国标";
          } else if (this.tableData5[i].standard == 2) {
            this.tableData5[i].standard = "省标";
          }
          if (this.tableData5[i].state == 0) {
            this.tableData5[i].stateful = "启用";
          } else {
            this.tableData5[i].stateful = "禁用";
          }
        }
      });
    },
    init6() {
      check_list({
        page: this.currentPage6,
        type: "配方颗粒(浸膏粉)",
        query: this.searchName6,
        companyId: this.activeName1,
      }).then((res) => {
        this.tableData6 = res.rows;
        this.total6 = res.total;
        for (let i = 0; i < this.tableData6.length; i++) {
          if (this.tableData6[i].standard == 1) {
            this.tableData6[i].standard = "国标";
          } else if (this.tableData6[i].standard == 2) {
            this.tableData6[i].standard = "省标";
          }
          if (this.tableData6[i].state == 0) {
            this.tableData6[i].stateful = "启用";
          } else {
            this.tableData6[i].stateful = "禁用";
          }
        }
      });
    },
    handleCurrentChange1(val) {
      this.currentPage1 = val;
      this.init1();
    },
    handleCurrentChange2(val) {
      this.currentPage2 = val;
      this.init2();
    },
    handleCurrentChange3(val) {
      this.currentPage3 = val;
      this.init3();
    },
    handleCurrentChange4(val) {
      this.currentPage4 = val;
      this.init4();
    },
    handleCurrentChange5(val) {
      this.currentPage5 = val;
      this.init5();
    },
    handleCurrentChange6(val) {
      this.currentPage6 = val;
      this.init6();
    },
    // tabs
    handleClick(tab, event) {},

    handleadded() {
      this.$router.push({
        path: "/managecheckingBasis/added",
        query: { type: this.activeName, sid: this.activeName1,standard:this.standard },
      });
    },
    //中药材编辑
    handleEdit(index, row) {
      this.$router.push({
        path: "/managecheckingBasis/edit",
        query: {
          id: row.id,
          type: this.activeName,
          sid: this.activeName1,
          standard:this.standard
        },
      });
    },

    //删除
    handleDelete1(index, row) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        check_delete(row.id).then((res) => {
          this.init1();
          this.$notify({
            title: "操作成功",
            message: "删除成功",
            type: "success",
          });
        });
      });
    },
    handleDelete2(index, row) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        check_delete(row.id).then((res) => {
          // this.tableData2.splice(row,1)
          // this.init1()
          this.init2();
          // this.init3()
          // this.init4()
          // this.init5()
          this.$notify({
            title: "操作成功",
            message: "删除成功",
            type: "success",
          });
        });
      });
    },
    handleDelete3(index, row) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        check_delete(row.id).then((res) => {
          // this.tableData3.splice(row,1)
          // this.init1()
          // this.init2()
          this.init3();
          // this.init4()
          // this.init5()
          this.$notify({
            title: "操作成功",
            message: "删除成功",
            type: "success",
          });
        });
      });
    },
    handleDelete4(index, row) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        check_delete(row.id).then((res) => {
          // this.tableData4.splice(row,1)
          // this.init1()
          // this.init2()
          // this.init3()
          this.init4();
          // this.init5()
          this.$notify({
            title: "操作成功",
            message: "删除成功",
            type: "success",
          });
        });
      });
    },
    handleDelete5(index, row) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        check_delete(row.id).then((res) => {
          // this.tableData5.splice(row,1)
          // this.init1()
          // this.init2()
          // this.init3()
          // this.init4()
          this.init5();
          this.$notify({
            title: "操作成功",
            message: "删除成功",
            type: "success",
          });
        });
      });
    },

    handleSearch1() {
      this.currentPage1 = 1;
      this.init1();
    },
    handleSearch2() {
      this.currentPage2 = 1;
      this.init2();
    },
    handleSearch3() {
      this.currentPage3 = 1;
      this.init3();
    },
    handleSearch4() {
      this.currentPage4 = 1;
      this.init4();
    },
    handleSearch5() {
      this.currentPage5 = 1;
      this.init5();
    },
    handleSearch6() {
      this.currentPage6 = 1;
      this.init6();
    },

    uploadonchange(file) {
      const loading = this.$loading({
        lock: true,
        text: "导入中，请勿刷新页面",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });

      let formData = new FormData();
      formData.append("file", file.raw);
      formData.append("companyId", this.activeName1);
      let config = {
        headers: { "Content-Type": "multipart/form-data" },
      };
      check_import(formData).then((res) => {
        if (res.code == 200) {
          loading.close();
          this.$alert("已导入" + res.data + "条", "导入成功", {
            confirmButtonText: "确定",
            callback: (action) => {},
          });
          // this.init();
          this.init1();
          this.init2();
          this.init3();
          this.init4();
          this.init5();
        } else {
          loading.close();
          this.$notify.error({
            title: "操作失败",
            message: "导入失败",
            type: "error",
          });
        }
      });
    },
    download() {
      //  window.location.href = "http://" + window.location.host + "/muban.xlsx";
      //   window.location.href = "http://" + window.location.host + "/工艺模版导入.xls";
      var data = { companyId: this.activeName1,type: this.activeName };
      let url = "";
      if (process.env.NODE_ENV == "development") {
        url = "http://" + window.location.host + "/api/check/export";
      } else {
        url = "http://" + window.location.host + "/check/export";
      }
      axios
        .request({
          url,
          responseType: "blob",
          method: "post",
          data,
        })
        .then((res) => {
          //此处有个坑。这里用content保存文件流，最初是content=res，但下载的test.xls里的内容如下图1，
          //检查了下才发现，后端对文件流做了一层封装，所以将content指向res.data即可
          //另外，流的转储属于浅拷贝，所以此处的content转储仅仅是便于理解，并没有实际作用=_=
          const content = res.data;
          const blob = new Blob([content]); //构造一个blob对象来处理数据
          const fileName = `检测依据${this.activeName}.xlsx`;

          //对于<a>标签，只有 Firefox 和 Chrome（内核） 支持 download 属性
          //IE10以上支持blob但是依然不支持download
          if ("download" in document.createElement("a")) {
            //支持a标签download的浏览器
            const link = document.createElement("a"); //创建a标签
            link.download = fileName; //a标签添加属性
            link.style.display = "none";
            link.href = URL.createObjectURL(blob);
            document.body.appendChild(link);
            link.click(); //执行下载
            URL.revokeObjectURL(link.href); //释放url
            document.body.removeChild(link); //释放标签
          } else {
            //其他浏览器
            navigator.msSaveBlob(blob, fileName);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  watch: {
    activeName1: {
      handler(newVal, oldVal) {
        // console.log(newVal)
        this.currentPage1 = 1;
        this.currentPage2 = 1;
        this.currentPage3 = 1;
        this.currentPage4 = 1;
        this.currentPage5 = 1;
        // this.currentPage6 = 1
        // console.log(this.$store.state.type)
        // this.activeName = "中药材";
        this.activeName1 = newVal;
        this.init1();
        this.init2();
        this.init3();
        this.init4();
        this.init5();
        this.init6();
      },
      deep: true,
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.upload-daoru {
  .el-upload {
    border: none;
    width: auto;
    height: auto;
    border-radius: 0;
    float: right;
    margin-right: 10px;
  }
}
.upload-demo .el-upload--text {
  border: none;
  width: auto;
  height: auto;
  border-radius: 0;
  float: right;
  margin-right: 10px;
}
.el-table {
  margin-top: 20px;
}
.el-pagination {
  text-align: center;
}
/* .el-row{ margin-bottom: 20px;} */
.el-pagination {
  text-align: center;
}
.el-col {
  margin-bottom: 0;
}
</style>
